﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.BLL;
using HNQXYJ.Model;

namespace HNQXYJ.HN_User
{
    public partial class UserUpdateRankLevel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request["id"]);
                Users user = new Users();
                user = new UsersBLL().GetUserDataById(id);
                this.txtUserName.Text = user.UserName;
                this.txtTrueName.Text = user.TrueName;
                this.txtTouchMehtod.Text = user.TouchMethod;
                this.txtNotes.Text = user.Notes;


            }

        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("UserMgrRankLevel.aspx");
        }

        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            Users user = new Users();
            user.ID = id;
            user.UserName = this.txtUserName.Text;
            user.TrueName = this.txtTrueName.Text.Trim();
            if (this.HidCountyCode.Value == "")
            {
                //市级管理员
                user.RankName = this.HidCityName.Value;
                user.RankLevel = this.HidCityCode.Value;
            }
            else
            {
                //县级管理员
                user.RankName = this.HidCityName.Value + this.HidCountyName.Value;
                user.RankLevel = this.HidCountyCode.Value;
            }
            user.TouchMethod = this.txtTouchMehtod.Text;
            user.AddDate = DateTime.Now;
            user.ErrTimes = 0;
            user.Notes = txtNotes.Text;

            bool flage = new UsersBLL().UpdateUserById(user);
            if (flage)
            {
                Response.Redirect("UserMgrRankLevel.aspx");
            }     
        }
    }
}